package com.atguigu.write;

import com.atguigu.bean.Movie;
import io.searchbox.client.JestClient;
import io.searchbox.client.JestClientFactory;
import io.searchbox.client.config.HttpClientConfig;
import io.searchbox.core.Index;

import java.io.IOException;
import java.util.HashMap;

public class Es01_SingleWrite {
    public static void main(String[] args) throws IOException {

        //1.创建客户端工厂
        JestClientFactory jestClientFactory = new JestClientFactory();

        //2.设置链接地址
        HttpClientConfig httpClientConfig = new HttpClientConfig.Builder("http://hadoop102:9200")
                .build();
        jestClientFactory.setHttpClientConfig(httpClientConfig);

        //3.获取客户端链接
        JestClient jestClient = jestClientFactory.getObject();

        //4.写入数据
//        HashMap<String, String> data = new HashMap<>();
//        data.put("id", "105");
//        data.put("name", "西游记");
        Movie movie = new Movie("106", "明朝那些事");

        Index index = new Index.Builder(movie)
                .index("movie_test220309")
                .type("_doc")
                .id("1006")
                .build();

        jestClient.execute(index);



        //关闭链接
        jestClient.shutdownClient();
    }
}
